/*
 * Copyright 2016 The BigDL Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intel.analytics.bigdl.dllib.nn

import com.intel.analytics.bigdl.dllib.tensor.Tensor
import com.intel.analytics.bigdl.dllib.utils.T
import com.intel.analytics.bigdl.dllib.utils.serializer.ModuleSerializationTest
import org.scalatest.{FlatSpec, Matchers}

class MaskPostProcessorSpec extends FlatSpec with Matchers {
  "MaskPostProcessor" should "be ok" in {
    val inputMaskLogits = Tensor[Float](T(T(T(
      T(8.9266e-01, 5.2952e-02, 8.8993e-01, 2.1737e-01, 4.3262e-01,
      9.1971e-01, 7.6453e-01, 2.1937e-01, 2.1589e-01, 2.5001e-01,
      8.6919e-01, 8.0406e-01),
      T(7.0763e-01, 7.2727e-01, 4.8777e-02, 2.7696e-01, 7.0037e-01,
        8.1201e-01, 2.4355e-01, 5.4897e-02, 4.8910e-01, 7.1544e-02,
        3.4121e-01, 2.0984e-01),
      T(5.2887e-01, 1.3025e-01, 6.7321e-02, 4.2251e-01, 3.9152e-01,
        1.7274e-01, 5.1561e-01, 6.2375e-01, 7.6026e-01, 1.4813e-01,
        4.5966e-01, 1.4207e-01),
      T(2.7198e-01, 7.6154e-01, 3.3004e-01, 9.7574e-01, 2.6676e-01,
        3.4621e-01, 2.5595e-02, 9.9852e-03, 9.4801e-01, 4.2668e-01,
        6.0820e-01, 4.8713e-01),
      T(8.9514e-01, 2.4535e-01, 5.4862e-01, 7.2516e-01, 6.0752e-01,
        8.6299e-01, 6.3599e-02, 3.3235e-01, 7.3556e-01, 3.1016e-01,
        5.1763e-01, 8.0128e-01),
      T(9.1450e-01, 7.9486e-02, 6.6234e-01, 3.0249e-01, 3.8758e-01,
        6.8105e-02, 4.2100e-01, 8.5701e-01, 7.3339e-01, 3.0515e-01,
        4.9443e-01, 7.3779e-01),
      T(3.8063e-01, 8.3248e-01, 5.8378e-01, 1.4540e-01, 3.2246e-01,
        2.0739e-03, 8.6754e-01, 2.8169e-01, 5.9686e-01, 8.6550e-01,
        8.6005e-01, 6.4949e-01),
      T(9.0238e-01, 7.3073e-01, 1.4320e-01, 2.7734e-01, 7.6483e-01,
        1.0894e-01, 5.6626e-01, 6.6160e-01, 3.1596e-01, 2.3878e-01,
        9.8633e-01, 4.9197e-01),
      T(3.7879e-01, 2.1094e-01, 1.6466e-01, 8.8588e-01, 2.0824e-01,
        8.3846e-01, 5.0154e-01, 7.4564e-01, 7.5496e-01, 1.8228e-01,
        2.3908e-01, 9.5290e-01),
      T(1.6153e-01, 5.6248e-02, 4.9601e-01, 8.9002e-01, 1.7391e-01,
        5.6027e-01, 2.3339e-01, 3.4646e-01, 2.3188e-01, 4.8249e-01,
        6.5249e-03, 9.3011e-01),
      T(1.9624e-01, 2.6868e-02, 2.7668e-01, 9.7361e-01, 3.4168e-01,
        2.3100e-01, 9.9714e-01, 1.7519e-01, 6.6320e-01, 5.4634e-01,
        5.1598e-01, 1.4175e-01),
      T(4.5882e-01, 5.5597e-01, 8.8264e-01, 2.9524e-01, 5.5032e-02,
        1.2057e-01, 6.7199e-01, 6.7714e-01, 9.0836e-01, 4.8373e-01,
        1.6290e-01, 5.3870e-01)),
      T(T(3.6951e-01, 1.3799e-01, 7.3234e-01, 4.1911e-02, 2.2635e-01,
        1.2024e-01, 4.6838e-01, 7.4153e-01, 1.3377e-01, 7.5208e-01,
        9.4293e-01, 1.8897e-02),
        T(3.1597e-02, 5.4314e-01, 9.6906e-01, 4.0233e-03, 9.4788e-02,
          6.3782e-01, 9.6362e-01, 8.4402e-01, 4.3295e-02, 2.3584e-01,
          4.5255e-01, 6.1947e-01),
        T(1.6893e-01, 9.4134e-01, 3.5109e-01, 1.0315e-01, 5.2498e-01,
          5.6462e-01, 2.2465e-01, 5.9791e-01, 8.6531e-01, 6.0136e-01,
          2.6199e-01, 3.0615e-01),
        T(9.6789e-01, 7.0924e-01, 1.9809e-01, 5.8839e-01, 6.7180e-01,
          5.1614e-01, 2.0701e-01, 7.1705e-01, 8.0150e-01, 8.2780e-01,
          9.9554e-01, 3.1920e-01),
        T(9.1926e-01, 6.2423e-01, 9.9339e-01, 3.0737e-01, 8.3251e-01,
          8.7844e-02, 1.1243e-01, 3.0151e-02, 6.4691e-01, 7.8775e-01,
          7.4950e-01, 4.6326e-01),
        T(7.9656e-01, 9.7216e-01, 7.7822e-01, 7.0151e-01, 6.8017e-01,
          5.7856e-01, 4.1357e-01, 7.8669e-01, 4.5162e-01, 2.3723e-01,
          7.0447e-02, 2.9159e-01),
        T(7.3562e-01, 4.1316e-01, 6.1123e-01, 4.4870e-01, 1.2226e-01,
          8.4052e-01, 2.0176e-01, 2.8235e-01, 4.9814e-01, 7.3970e-01,
          3.0268e-01, 7.4783e-01),
        T(8.9801e-01, 4.0995e-02, 5.7727e-01, 3.0002e-01, 4.5203e-01,
          6.3573e-01, 5.3683e-01, 7.8926e-01, 7.1823e-01, 2.7769e-01,
          1.5565e-01, 5.6815e-01),
        T(3.9114e-02, 1.4810e-01, 5.8096e-01, 4.7103e-01, 1.4103e-01,
          6.8295e-01, 4.6592e-01, 4.9047e-01, 2.6970e-01, 1.6821e-01,
          7.0323e-01, 4.0817e-01),
        T(7.5532e-01, 4.2603e-01, 3.2512e-01, 7.2264e-01, 5.3028e-01,
          4.7349e-01, 1.5825e-01, 1.9719e-01, 1.2144e-01, 7.8264e-01,
          5.8553e-01, 7.0413e-01),
        T(9.4902e-01, 2.1282e-01, 1.1331e-01, 4.1740e-01, 5.2139e-02,
          3.9091e-01, 3.1151e-01, 1.4666e-01, 5.2448e-01, 9.1924e-01,
          1.6230e-02, 7.1487e-01),
        T(7.3130e-01, 3.2317e-01, 3.3967e-01, 9.4663e-02, 5.2202e-01,
          1.3584e-01, 9.8951e-01, 5.7226e-01, 3.0454e-01, 9.8038e-01,
          7.4580e-02, 6.8083e-01)),
      T(T(3.7845e-01, 2.5805e-01, 5.8910e-01, 4.1663e-01, 9.6243e-01,
        1.9386e-01, 1.4914e-02, 7.0933e-01, 7.7398e-01, 3.6151e-01,
        8.0886e-01, 7.5896e-01),
        T(9.4524e-01, 1.5564e-01, 9.6360e-01, 5.2341e-02, 6.3949e-01,
          8.6984e-01, 6.1065e-02, 8.0362e-01, 6.6701e-01, 5.8622e-01,
          6.0720e-01, 3.1504e-01),
        T(8.8964e-01, 3.3164e-01, 1.4276e-01, 2.8760e-01, 3.8244e-01,
          7.0435e-01, 8.8303e-01, 2.6475e-01, 2.8730e-02, 3.7651e-01,
          4.2154e-01, 4.1290e-01),
        T(3.6253e-01, 8.6923e-01, 9.4091e-01, 6.4615e-01, 8.5160e-01,
          4.7871e-01, 8.3564e-01, 2.7992e-01, 5.9532e-01, 8.3653e-01,
          2.5293e-01, 2.9880e-01),
        T(9.3729e-01, 7.7754e-01, 1.4048e-01, 7.3982e-01, 1.6225e-01,
          9.2290e-01, 2.1349e-01, 2.7212e-01, 5.4940e-02, 8.8719e-01,
          7.3515e-01, 3.7991e-02),
        T(5.0607e-02, 1.8035e-01, 8.4393e-01, 9.4252e-01, 7.4845e-01,
          4.2559e-01, 1.9585e-01, 1.4565e-01, 9.6164e-01, 1.6263e-01,
          4.4311e-01, 8.8596e-01),
        T(3.7587e-01, 5.5457e-01, 6.5632e-01, 4.9692e-01, 5.9535e-01,
          1.4029e-01, 8.7729e-01, 2.1662e-01, 6.1966e-01, 1.9519e-01,
          8.8612e-01, 7.3382e-01),
        T(8.9095e-01, 4.7047e-01, 1.2147e-01, 8.9488e-01, 9.4951e-01,
          9.3880e-01, 8.3849e-01, 9.1317e-01, 3.4744e-01, 7.8700e-01,
          6.3877e-01, 2.4145e-01),
        T(3.4664e-01, 2.0148e-01, 4.6785e-01, 5.8741e-01, 7.8034e-01,
          4.6743e-03, 1.6360e-01, 6.4379e-01, 2.8184e-01, 1.9088e-01,
          4.4669e-01, 1.4079e-01),
        T(9.1668e-01, 1.4031e-01, 8.5721e-01, 7.8864e-01, 8.6129e-01,
          6.2736e-01, 8.8479e-01, 2.9379e-01, 6.4125e-02, 8.2475e-01,
          4.7486e-01, 1.2658e-01),
        T(5.6112e-01, 3.5820e-01, 2.4334e-01, 6.1531e-01, 6.4265e-01,
          3.2820e-01, 7.3462e-01, 8.1017e-01, 6.1421e-01, 9.1728e-01,
          4.9037e-01, 8.3750e-01),
        T(2.8230e-01, 6.3305e-01, 5.1096e-01, 5.9111e-01, 8.0834e-01,
          6.3176e-01, 6.1346e-01, 5.7333e-01, 8.2617e-01, 7.0671e-01,
          6.1842e-01, 6.3352e-01)),
      T(T(5.0607e-01, 7.1042e-01, 7.3635e-01, 9.1421e-01, 4.7531e-01,
        4.3613e-02, 9.6058e-01, 3.3791e-01, 2.7063e-01, 6.3848e-01,
        4.4701e-01, 4.9088e-01),
        T(8.7411e-01, 9.2071e-01, 3.0666e-02, 8.8298e-01, 9.9636e-01,
          7.5149e-01, 6.3854e-01, 1.4863e-01, 9.0349e-01, 4.6163e-01,
          4.0322e-01, 6.8579e-01),
        T(6.4658e-01, 4.2182e-01, 8.4221e-01, 2.2041e-01, 9.3936e-01,
          1.4988e-01, 7.5577e-01, 7.3340e-01, 9.1164e-01, 9.7166e-01,
          6.7454e-01, 8.9873e-01),
        T(3.2060e-01, 4.2647e-01, 8.5995e-01, 8.6938e-02, 8.8237e-01,
          7.7610e-01, 2.8524e-01, 3.0443e-01, 6.9658e-01, 4.5850e-01,
          6.7079e-01, 7.6531e-01),
        T(3.9561e-01, 1.5111e-01, 8.7156e-01, 1.1029e-01, 7.7353e-01,
          2.7391e-01, 1.2001e-01, 5.7791e-02, 2.0982e-01, 6.8289e-01,
          2.1882e-01, 3.3337e-01),
        T(9.1951e-01, 5.2202e-01, 5.3638e-01, 2.2157e-01, 5.3178e-01,
          1.8821e-02, 8.1969e-02, 7.1356e-01, 1.9674e-01, 2.4707e-01,
          5.2136e-01, 7.3031e-01),
        T(5.7401e-01, 4.4023e-01, 6.3246e-01, 8.2798e-01, 4.7964e-02,
          6.5309e-01, 7.3456e-01, 9.4116e-01, 3.6138e-01, 6.8498e-01,
          8.8140e-01, 4.8346e-01),
        T(9.8992e-01, 5.6812e-01, 7.1927e-01, 6.9039e-01, 8.9107e-01,
          4.3549e-01, 3.6060e-01, 1.2740e-01, 2.4853e-01, 4.2677e-01,
          1.7630e-01, 6.1553e-01),
        T(9.8307e-01, 6.6770e-02, 3.0151e-01, 8.6250e-01, 4.9009e-01,
          9.1143e-01, 3.3896e-01, 3.7378e-01, 5.6470e-01, 7.2127e-01,
          5.7915e-01, 4.4921e-01),
        T(3.7054e-01, 1.6627e-01, 7.5695e-01, 3.9457e-01, 7.6924e-01,
          2.9941e-01, 8.0577e-01, 1.0130e-03, 5.8356e-01, 7.0865e-01,
          2.3457e-01, 3.0518e-01),
        T(8.1758e-02, 6.6615e-02, 8.9409e-01, 8.5562e-03, 1.7579e-01,
          2.8181e-01, 1.1119e-01, 1.4564e-01, 2.2013e-01, 3.5086e-01,
          3.5315e-01, 9.8622e-01),
        T(8.6330e-01, 8.2877e-01, 4.9915e-01, 9.0538e-01, 7.2534e-01,
          3.0035e-01, 2.2448e-01, 9.0566e-01, 9.0814e-01, 4.7077e-01,
          9.0666e-01, 4.9276e-01)),
      T(T(6.0330e-01, 7.7644e-01, 2.6807e-01, 7.3722e-01, 7.4469e-01,
        9.6685e-01, 7.6045e-01, 6.3858e-01, 8.7433e-01, 5.5773e-01,
        8.6310e-01, 2.5389e-01),
        T(1.2813e-01, 2.3047e-01, 2.2435e-01, 2.8524e-01, 8.0222e-01,
          3.3595e-01, 4.6029e-01, 8.0308e-01, 9.3254e-02, 2.8119e-01,
          5.9755e-01, 8.4112e-01),
        T(9.6892e-01, 1.2281e-01, 6.9214e-01, 9.0326e-01, 9.5204e-01,
          5.1845e-01, 1.5491e-01, 1.5469e-03, 8.5292e-01, 7.0488e-01,
          2.4065e-01, 5.9097e-01),
        T(2.1134e-01, 9.3985e-01, 3.9389e-01, 6.9252e-01, 3.3950e-01,
          9.3430e-01, 9.3301e-02, 8.5893e-01, 5.3110e-02, 4.9273e-01,
          3.6012e-01, 6.2802e-01),
        T(3.6899e-01, 8.1862e-01, 3.1929e-01, 2.7797e-01, 4.0913e-01,
          3.8646e-01, 6.6694e-01, 9.2391e-01, 4.6419e-01, 2.7967e-01,
          1.9019e-01, 1.1107e-01),
        T(4.4420e-01, 7.1508e-01, 2.8506e-01, 6.4572e-01, 6.3682e-01,
          6.1773e-01, 3.9028e-01, 1.2321e-01, 6.7507e-01, 4.6599e-01,
          5.4475e-01, 5.3482e-01),
        T(5.8249e-02, 7.2601e-02, 7.6782e-01, 4.3893e-01, 9.8503e-01,
          5.2492e-01, 5.6102e-02, 5.3040e-01, 8.1769e-02, 9.1074e-01,
          7.0111e-01, 2.0004e-02),
        T(8.5650e-01, 3.2337e-01, 2.8856e-01, 3.4956e-01, 3.6710e-01,
          4.1961e-01, 8.1825e-01, 8.4757e-02, 6.3473e-01, 1.9217e-01,
          7.7529e-01, 5.3391e-01),
        T(4.8624e-01, 6.9539e-01, 2.2359e-01, 3.2987e-01, 7.7391e-01,
          9.0060e-01, 1.2243e-01, 4.7818e-01, 1.5706e-01, 8.9221e-01,
          5.2529e-01, 9.7300e-01),
        T(3.6214e-01, 7.2031e-01, 9.9981e-01, 4.6628e-01, 4.4199e-01,
          7.2773e-01, 2.7725e-01, 1.2637e-01, 9.1999e-01, 4.6192e-01,
          2.9125e-01, 6.4114e-01),
        T(4.6364e-01, 3.1205e-01, 8.0984e-01, 6.0272e-01, 1.1197e-01,
          7.9695e-01, 7.0654e-01, 1.1986e-01, 1.9671e-01, 7.9255e-01,
          3.3005e-01, 6.7057e-01),
        T(5.3130e-01, 9.2726e-01, 1.4569e-01, 1.0613e-01, 8.4280e-01,
          3.1146e-01, 4.1880e-01, 7.2137e-01, 5.7902e-01, 5.8861e-01,
          8.7850e-02, 4.9692e-01)),
      T(T(9.9426e-01, 6.3925e-02, 4.1810e-01, 8.7817e-02, 6.3861e-01,
        9.5431e-01, 1.1252e-01, 9.7455e-01, 8.4083e-01, 7.6313e-01,
        4.5497e-01, 5.1995e-01),
        T(5.2983e-01, 4.6764e-01, 6.6489e-01, 8.9104e-01, 8.1868e-01,
          3.7402e-01, 2.4543e-01, 7.9696e-02, 2.0057e-01, 1.4047e-01,
          6.5510e-01, 5.3253e-01),
        T(8.6106e-01, 8.1852e-02, 7.4850e-01, 4.7536e-01, 7.9111e-02,
          1.7290e-02, 1.6128e-02, 7.0112e-01, 3.5013e-01, 9.0334e-01,
          1.7720e-02, 7.2688e-01),
        T(6.4419e-01, 3.4589e-01, 9.7112e-01, 2.9524e-01, 7.2176e-01,
          7.5968e-01, 2.0192e-01, 6.0229e-01, 3.4158e-01, 8.9733e-01,
          2.9908e-01, 2.8840e-01),
        T(2.9399e-01, 2.4156e-01, 7.2828e-01, 6.9347e-02, 6.3273e-01,
          7.6171e-01, 4.3995e-01, 3.4023e-01, 1.5208e-01, 6.8464e-01,
          3.1819e-01, 8.6317e-01),
        T(6.1231e-01, 8.5787e-01, 5.1518e-01, 1.9815e-01, 3.0353e-01,
          4.4699e-01, 2.1292e-01, 7.8122e-01, 2.1446e-01, 2.8313e-01,
          4.7488e-01, 5.5359e-02),
        T(6.3909e-01, 1.1758e-01, 7.0805e-01, 5.2210e-02, 6.1401e-01,
          6.8369e-01, 2.9849e-03, 8.1363e-01, 7.7599e-01, 2.7725e-01,
          6.8330e-02, 8.9432e-01),
        T(8.8278e-01, 5.1701e-01, 5.1782e-01, 4.7146e-01, 6.8989e-02,
          3.2362e-01, 6.6077e-01, 2.1085e-01, 3.1761e-01, 2.4118e-01,
          2.3992e-02, 9.5169e-01),
        T(9.9865e-01, 5.6737e-01, 5.5085e-01, 7.8889e-01, 9.9161e-01,
          1.7742e-01, 2.3268e-02, 6.6724e-01, 8.5692e-01, 6.0319e-01,
          7.7331e-01, 9.6312e-02),
        T(5.8388e-01, 9.3255e-01, 3.2831e-01, 6.4402e-01, 8.1246e-01,
          1.7721e-01, 9.5142e-01, 6.3702e-01, 9.2875e-01, 8.0767e-01,
          6.1356e-01, 8.5396e-01),
        T(5.8560e-01, 9.6354e-01, 2.1267e-01, 3.1965e-01, 4.4926e-01,
          2.1777e-01, 9.8542e-01, 6.0431e-01, 8.2043e-01, 6.4950e-01,
          7.3367e-01, 2.7812e-01),
        T(2.1872e-01, 3.2132e-01, 9.0542e-01, 3.7910e-01, 6.6219e-01,
          7.7696e-01, 6.1790e-01, 9.1962e-01, 2.8445e-01, 9.2130e-01,
          8.5399e-01, 7.4798e-01))),
      T(T(T(9.0210e-01, 6.5141e-01, 3.6298e-01, 6.7448e-01, 8.9387e-01,
        5.2916e-01, 9.4324e-01, 9.1115e-01, 7.0097e-01, 4.0427e-01,
        6.2243e-01, 7.8750e-01),
        T(9.7987e-01, 7.6816e-01, 6.7514e-01, 8.9619e-01, 7.4680e-01,
          6.5120e-01, 8.1931e-01, 1.4049e-01, 4.3666e-01, 1.5257e-01,
          6.2446e-01, 2.6906e-01),
        T(9.2222e-01, 6.9246e-01, 4.4534e-01, 9.1264e-01, 4.1092e-01,
          9.8803e-01, 2.7172e-01, 7.0141e-01, 3.8303e-01, 1.8324e-01,
          4.5950e-02, 8.2282e-01),
        T(3.1667e-01, 9.9222e-01, 5.6315e-02, 8.2372e-02, 8.5611e-01,
          8.2646e-01, 2.1964e-01, 9.0197e-01, 7.8398e-01, 7.7979e-01,
          9.0715e-01, 7.0309e-01),
        T(4.5655e-01, 9.1914e-01, 1.6741e-01, 5.2516e-01, 7.4684e-01,
          8.4159e-01, 1.4773e-01, 4.6644e-02, 1.1681e-01, 2.7376e-01,
          5.6858e-01, 9.5820e-01),
        T(3.3443e-01, 2.0986e-01, 8.6418e-01, 7.0565e-01, 3.2223e-01,
          5.6540e-01, 6.2196e-02, 9.0146e-01, 8.3877e-01, 9.3418e-01,
          8.3776e-02, 6.1329e-01),
        T(4.5451e-01, 5.7976e-02, 8.9474e-01, 4.0244e-01, 4.5898e-01,
          8.3933e-01, 5.6322e-01, 6.3615e-01, 7.8164e-01, 8.3445e-01,
          5.2768e-01, 5.2123e-01),
        T(9.6326e-01, 8.2142e-01, 8.5328e-02, 4.0131e-01, 8.5544e-01,
          4.7253e-01, 2.9534e-01, 7.5735e-01, 4.5469e-01, 4.8478e-01,
          4.4163e-01, 9.8932e-01),
        T(2.9878e-01, 7.5048e-01, 2.2156e-01, 2.4083e-01, 4.9565e-01,
          8.5755e-01, 1.3513e-01, 6.4942e-01, 3.5500e-01, 8.1927e-01,
          5.6745e-01, 7.6181e-02),
        T(6.5556e-01, 8.9203e-01, 2.7140e-01, 7.9838e-01, 9.4998e-01,
          7.8900e-01, 4.3311e-01, 2.9009e-01, 3.7727e-01, 1.1040e-01,
          6.5879e-01, 4.3932e-01),
        T(8.1362e-01, 7.5874e-01, 6.9438e-02, 7.9095e-01, 7.6562e-01,
          3.9892e-01, 4.1663e-01, 8.9926e-01, 6.7283e-01, 7.3770e-01,
          5.3241e-01, 4.8315e-02),
        T(1.7418e-01, 7.8675e-01, 9.2190e-01, 5.5140e-01, 5.4437e-01,
          8.9596e-01, 1.9384e-01, 3.2540e-01, 1.4244e-01, 9.0375e-01,
          3.2466e-02, 9.3776e-01)),
        T(T(9.0323e-01, 1.2442e-01, 7.5697e-01, 3.4532e-01, 6.6509e-01,
          1.1620e-01, 2.5798e-01, 5.2732e-01, 4.5535e-01, 8.3346e-02,
          4.3552e-01, 1.5638e-01),
          T(3.0902e-01, 5.8697e-01, 9.0960e-01, 6.9490e-01, 4.7682e-01,
            9.8356e-01, 3.7834e-01, 4.5490e-01, 5.7124e-01, 4.3294e-01,
            2.8453e-01, 1.5870e-01),
          T(6.5173e-01, 6.4205e-01, 7.3660e-01, 1.8330e-01, 4.7001e-01,
            9.7033e-02, 1.3909e-01, 2.2954e-01, 4.3124e-01, 2.0252e-01,
            8.9110e-01, 6.3637e-02),
          T(3.6709e-01, 4.5333e-01, 9.5578e-01, 7.7314e-01, 1.7356e-01,
            5.8386e-01, 8.2247e-01, 6.0875e-02, 8.9972e-01, 9.2506e-03,
            4.3395e-01, 1.3068e-01),
          T(6.0298e-01, 5.9193e-01, 3.4498e-01, 9.4268e-01, 2.9396e-01,
            3.1238e-01, 8.1642e-01, 8.2967e-01, 1.1930e-01, 7.2229e-01,
            4.4235e-01, 6.5560e-01),
          T(6.7752e-01, 5.7697e-01, 5.7601e-01, 4.0516e-01, 5.5048e-01,
            6.7224e-01, 9.7373e-01, 5.1365e-01, 6.8733e-01, 5.3922e-01,
            1.9542e-01, 4.9333e-01),
          T(1.1277e-02, 4.1857e-01, 2.9706e-01, 4.0556e-01, 7.7204e-01,
            5.6031e-02, 9.8012e-01, 4.1539e-01, 5.4665e-01, 4.0964e-01,
            6.0157e-02, 7.7327e-01),
          T(7.2221e-01, 3.3551e-01, 8.8177e-01, 5.7280e-01, 7.4597e-01,
            5.6041e-01, 2.6174e-02, 2.7592e-01, 4.5655e-01, 6.1223e-01,
            4.0727e-01, 4.5043e-01),
          T(6.7885e-01, 8.9619e-01, 5.1936e-01, 7.8076e-01, 9.6203e-01,
            4.7000e-01, 7.4252e-01, 3.3943e-01, 8.7667e-01, 1.6725e-01,
            2.1884e-01, 8.8516e-01),
          T(9.7008e-01, 8.6133e-01, 5.2964e-01, 7.6452e-01, 4.9735e-01,
            2.5782e-01, 8.6329e-01, 1.1120e-01, 7.4513e-02, 6.9196e-01,
            6.6461e-01, 7.5456e-01),
          T(3.3531e-01, 8.7111e-01, 6.9098e-01, 3.2132e-01, 1.8271e-01,
            7.8872e-01, 2.0267e-01, 4.0926e-01, 4.3699e-01, 7.4968e-01,
            7.6315e-01, 5.2738e-01),
          T(5.5032e-01, 7.1685e-01, 6.1557e-01, 8.8345e-01, 3.5772e-01,
            9.4135e-01, 6.6356e-01, 9.7049e-01, 7.2569e-01, 2.0204e-01,
            6.8523e-01, 4.8523e-01)),
        T(T(9.0309e-01, 5.9105e-01, 4.1597e-01, 8.2724e-01, 5.5213e-01,
          8.1416e-01, 7.6330e-01, 9.1338e-01, 7.9250e-01, 7.0501e-01,
          3.9490e-01, 2.0043e-01),
          T(6.0797e-01, 1.7537e-01, 9.7802e-02, 1.7216e-01, 1.9885e-01,
            1.4212e-02, 7.3420e-01, 5.5526e-01, 4.4673e-01, 2.4253e-02,
            7.6748e-01, 9.7852e-01),
          T(6.6502e-01, 8.1590e-01, 8.9544e-01, 3.9516e-01, 2.8384e-02,
            9.7759e-01, 7.6895e-01, 6.3234e-01, 7.3652e-01, 9.3888e-01,
            2.5803e-01, 4.4742e-01),
          T(6.9651e-01, 8.0287e-01, 9.3013e-01, 4.5883e-01, 2.6025e-01,
            5.8348e-01, 4.7425e-02, 3.3193e-01, 3.1901e-01, 8.7463e-01,
            2.1334e-02, 1.3368e-02),
          T(1.4338e-01, 5.4759e-01, 4.5652e-01, 3.3190e-01, 7.2900e-01,
            6.7779e-01, 8.7200e-01, 3.7033e-01, 9.6735e-01, 5.3604e-01,
            6.5868e-01, 9.9554e-01),
          T(9.7921e-01, 2.0708e-01, 6.8043e-01, 8.8920e-01, 8.2703e-01,
            3.4734e-02, 4.8729e-01, 8.2527e-02, 8.5335e-01, 1.4431e-01,
            9.6512e-01, 3.2994e-01),
          T(9.1532e-01, 5.5083e-01, 1.2981e-01, 5.1155e-01, 5.6736e-01,
            7.3879e-01, 3.9355e-01, 9.3673e-01, 7.5139e-01, 1.9242e-01,
            7.3676e-01, 2.3396e-01),
          T(3.9342e-01, 2.8874e-01, 1.7627e-01, 2.2692e-01, 5.6504e-01,
            4.5509e-01, 9.3396e-01, 6.2188e-01, 9.9719e-01, 1.4317e-01,
            5.2048e-02, 3.4573e-01),
          T(9.7216e-01, 4.5764e-01, 8.6023e-01, 9.4401e-01, 3.5064e-01,
            5.7555e-01, 3.1853e-01, 6.9617e-01, 3.6052e-01, 9.4507e-01,
            8.6924e-01, 9.2480e-01),
          T(6.3758e-01, 1.7282e-01, 1.8704e-01, 8.7714e-01, 9.1231e-01,
            4.0208e-01, 1.2835e-01, 9.7075e-01, 8.3198e-01, 4.2253e-01,
            3.9210e-01, 8.0198e-01),
          T(1.2100e-01, 9.1121e-01, 9.7795e-01, 6.7801e-01, 3.4470e-01,
            8.9417e-02, 7.3433e-01, 8.2596e-02, 4.4342e-01, 9.8175e-01,
            2.5478e-01, 4.2414e-01),
          T(6.8528e-01, 7.2200e-01, 1.7320e-01, 4.5800e-01, 4.5385e-02,
            7.3794e-01, 8.7415e-01, 9.8378e-01, 2.7702e-01, 5.6056e-01,
            1.3569e-01, 3.7602e-01)),
        T(T(4.9341e-01, 6.3008e-01, 4.1943e-01, 5.3855e-01, 8.7447e-01,
          5.7822e-04, 9.5946e-01, 5.2798e-01, 7.3620e-02, 6.9500e-01,
          4.0663e-02, 6.8594e-01),
          T(7.2926e-01, 7.5355e-01, 2.3635e-02, 3.5077e-01, 8.7403e-01,
            8.1511e-01, 4.7338e-01, 9.6479e-01, 2.2138e-02, 2.4239e-01,
            2.7445e-01, 9.1811e-01),
          T(9.9610e-01, 7.7491e-01, 6.1244e-01, 4.9763e-01, 5.0898e-01,
            4.9950e-01, 6.4411e-02, 8.0080e-01, 3.2128e-01, 4.6742e-01,
            7.8235e-01, 3.5412e-01),
          T(7.0437e-01, 4.4210e-01, 5.3852e-01, 8.1157e-01, 4.8433e-03,
            2.8846e-01, 3.1216e-01, 6.7776e-01, 1.3221e-01, 2.6775e-01,
            1.8309e-01, 6.8747e-01),
          T(1.8531e-01, 7.0487e-01, 9.2242e-01, 8.8278e-01, 9.1845e-01,
            1.2302e-02, 1.4697e-01, 1.0295e-01, 4.4998e-01, 9.5336e-01,
            3.5404e-02, 6.8165e-01),
          T(1.5035e-02, 5.4473e-01, 6.3069e-02, 1.1463e-02, 8.9119e-01,
            5.6985e-01, 5.2152e-01, 6.1950e-01, 2.8115e-01, 2.0622e-01,
            4.2224e-01, 8.6679e-01),
          T(9.8959e-01, 6.3546e-02, 2.6587e-01, 1.7856e-01, 1.9692e-01,
            4.3182e-01, 3.7267e-01, 1.4967e-03, 8.3172e-01, 9.8789e-01,
            6.7132e-01, 7.0667e-01),
          T(7.1877e-01, 5.7644e-01, 4.9500e-01, 9.1099e-01, 2.3985e-01,
            6.3355e-01, 5.1885e-01, 6.2005e-02, 4.7853e-01, 3.6728e-01,
            8.6522e-01, 1.5128e-02),
          T(2.3488e-01, 7.4914e-01, 1.7108e-01, 6.2114e-01, 3.0221e-01,
            2.2339e-01, 4.4461e-01, 9.3693e-02, 9.4324e-01, 3.6998e-01,
            1.2593e-01, 7.1708e-01),
          T(2.9746e-01, 3.8052e-01, 8.0276e-01, 4.3276e-01, 1.8061e-02,
            2.7508e-01, 5.5288e-01, 6.8793e-01, 9.9519e-01, 7.7957e-01,
            9.8120e-01, 3.4021e-01),
          T(8.2095e-01, 7.4965e-01, 7.1272e-01, 6.4533e-01, 5.2148e-01,
            4.9511e-01, 6.9354e-01, 4.0741e-01, 5.9655e-01, 6.4465e-01,
            3.4886e-01, 8.6132e-01),
          T(1.4155e-02, 5.9273e-01, 1.1606e-01, 7.0520e-01, 6.9800e-01,
            2.8105e-01, 9.3451e-01, 3.8558e-01, 7.6324e-01, 3.3492e-01,
            4.0761e-01, 4.1239e-01)),
        T(T(4.1839e-02, 9.1334e-01, 2.5767e-01, 2.5064e-01, 8.8775e-02,
          5.3894e-01, 8.4828e-01, 7.7168e-01, 9.4614e-01, 1.3583e-01,
          5.1885e-01, 7.6101e-02),
          T(4.0845e-01, 1.9687e-01, 1.1023e-01, 2.0471e-01, 5.5339e-01,
            9.5043e-01, 3.6905e-01, 2.7399e-01, 9.3949e-01, 6.3068e-01,
            2.9279e-01, 7.4781e-01),
          T(6.0757e-02, 1.9193e-01, 3.4410e-01, 7.5923e-01, 9.0350e-01,
            5.3751e-01, 9.3952e-01, 8.7902e-02, 9.0091e-01, 4.8934e-01,
            8.5773e-01, 2.3732e-01),
          T(9.0992e-01, 6.4511e-01, 9.7351e-01, 1.6476e-02, 9.3126e-02,
            8.7006e-01, 3.8926e-01, 7.3037e-01, 9.1690e-01, 3.4040e-01,
            3.3211e-01, 2.7740e-01),
          T(4.9831e-01, 3.3797e-01, 9.9430e-01, 2.3396e-01, 9.0614e-03,
            8.2772e-01, 6.2330e-02, 2.9306e-01, 8.2680e-02, 6.0866e-01,
            2.1655e-01, 8.9222e-01),
          T(7.8280e-01, 8.3864e-01, 4.3997e-01, 5.7485e-01, 2.7450e-01,
            4.7448e-01, 4.8375e-03, 1.0803e-01, 9.5425e-01, 7.1734e-01,
            6.0820e-02, 4.0524e-01),
          T(6.3443e-01, 4.9199e-01, 2.9210e-01, 9.0821e-01, 8.3093e-01,
            1.0038e-01, 8.1419e-01, 9.3704e-01, 9.8328e-01, 2.0146e-02,
            5.3379e-01, 9.4974e-01),
          T(8.9382e-01, 9.5493e-01, 9.8511e-01, 8.0311e-01, 1.2260e-01,
            3.3806e-01, 3.7316e-01, 6.2515e-01, 7.4436e-01, 2.7742e-01,
            3.9258e-02, 1.7999e-01),
          T(2.5323e-01, 5.0693e-01, 2.6216e-02, 6.4093e-01, 1.4145e-01,
            9.3613e-03, 6.2346e-01, 7.8594e-01, 3.3479e-01, 6.5158e-01,
            1.6063e-01, 9.8595e-01),
          T(5.1119e-01, 1.1334e-01, 3.6563e-01, 6.3141e-01, 2.0313e-01,
            8.0755e-01, 1.5606e-01, 7.5401e-01, 8.0947e-01, 9.7372e-01,
            7.8793e-01, 3.5387e-01),
          T(7.4490e-01, 8.4498e-01, 9.0372e-02, 6.4984e-01, 7.4610e-01,
            6.1592e-01, 1.8846e-01, 4.4623e-01, 7.9127e-01, 9.3616e-01,
            4.4810e-01, 1.2915e-01),
          T(2.0279e-01, 4.0912e-02, 9.7509e-01, 9.6308e-01, 2.1670e-01,
            1.3103e-01, 3.9296e-01, 3.5319e-01, 6.6782e-01, 5.8237e-01,
            5.4398e-01, 4.8577e-01)),
        T(T(7.2174e-01, 2.6102e-02, 6.4283e-01, 5.8040e-02, 9.1795e-01,
          7.9103e-01, 1.7339e-01, 4.4441e-01, 4.0597e-01, 5.1714e-01,
          8.1261e-01, 9.0005e-01),
          T(3.3585e-02, 7.6136e-01, 1.5193e-01, 9.3905e-01, 7.7138e-02,
            3.0083e-01, 8.8580e-01, 4.2620e-03, 6.3033e-01, 9.6322e-01,
            3.9882e-01, 3.5515e-01),
          T(5.1523e-01, 3.3807e-01, 9.0054e-01, 8.2077e-01, 3.6295e-01,
            3.5788e-01, 7.4880e-01, 9.7070e-01, 3.5812e-01, 8.0819e-01,
            9.0567e-01, 8.2637e-01),
          T(9.9231e-01, 5.6117e-02, 8.1108e-01, 6.5661e-01, 5.1613e-01,
            7.3686e-01, 2.6683e-01, 3.0752e-01, 6.4153e-01, 7.2429e-01,
            9.1566e-01, 5.0017e-01),
          T(7.2460e-01, 2.2245e-01, 1.2162e-03, 7.8895e-01, 2.5927e-01,
            7.7986e-01, 9.5457e-01, 1.7036e-01, 8.7724e-01, 5.7733e-01,
            7.3935e-01, 5.9932e-01),
          T(6.9864e-01, 8.1021e-01, 7.4214e-02, 5.2962e-01, 2.5611e-01,
            8.7787e-01, 4.4532e-01, 8.9145e-01, 3.0780e-01, 2.8806e-01,
            2.1132e-01, 8.4222e-01),
          T(8.0758e-01, 4.2134e-01, 2.8893e-01, 4.0820e-01, 5.3765e-01,
            4.5207e-01, 1.6186e-01, 9.4840e-01, 8.5380e-01, 9.8164e-02,
            5.2123e-01, 3.9020e-01),
          T(9.6101e-01, 5.2674e-01, 5.4770e-01, 1.5045e-01, 7.0950e-01,
            3.9006e-01, 3.1002e-01, 1.7049e-01, 7.6328e-01, 1.9298e-01,
            7.5822e-01, 6.1642e-01),
          T(9.9112e-01, 9.4758e-01, 7.0602e-03, 3.6465e-02, 9.4971e-01,
            5.1071e-01, 7.0599e-01, 2.8420e-01, 2.8210e-01, 7.1894e-01,
            7.7572e-01, 3.6888e-01),
          T(8.7262e-01, 3.1759e-01, 7.7522e-01, 4.4778e-01, 2.7879e-01,
            4.2009e-01, 5.5572e-01, 9.5537e-01, 5.5494e-01, 1.5535e-01,
            1.1270e-01, 6.7605e-01),
          T(3.7349e-01, 7.3304e-01, 5.8971e-01, 1.7675e-01, 9.4888e-01,
            8.3404e-02, 8.1588e-01, 9.1072e-01, 1.3691e-01, 7.5133e-01,
            7.1789e-01, 3.4329e-01),
          T(8.2344e-01, 3.9210e-01, 2.0472e-01, 2.2641e-01, 2.8660e-01,
            3.3381e-01, 3.0478e-01, 1.1062e-01, 4.9216e-01, 3.3757e-02,
            1.9666e-01, 3.8566e-01)))))

    val bbox = Tensor[Float](T(T(1.0f, 3.0f, 2.0f, 6.0f), T(3.0f, 5.0f, 6.0f, 10.0f)))
    val imageInfo = Tensor[Float](T(10, 15))
    val labels = Tensor[Float](T(2, 4))

    val layer = new MaskPostProcessor()

    val output = layer.forward(T(inputMaskLogits, labels))

    val expectedOutput = Tensor[Float](T(T(T(
        T(0.5934, 0.5641569, 0.6431586, 0.6026766, 0.7236081, 0.5483138, 0.50372845, 0.67025316,
          0.68438125, 0.58940595, 0.6918666, 0.6811279),
        T(0.7201, 0.53883165, 0.723842, 0.51308227, 0.6546382, 0.70471245, 0.51526153, 0.6907483,
          0.66083336, 0.6424974, 0.6473018, 0.578115),
        T(0.7088, 0.5821584, 0.5356295, 0.5714085, 0.59446144, 0.66915154, 0.70744973, 0.5658036,
          0.507182, 0.5930311, 0.60385174, 0.60178304),
        T(0.5896, 0.70458543, 0.71928346, 0.65614235, 0.7009027, 0.6174432, 0.6975462, 0.5695266,
          0.64458483, 0.69773394, 0.56289756, 0.57414913),
        T(0.71855193, 0.68514967, 0.5350624, 0.6769565, 0.54047376, 0.7156327, 0.5531707,
          0.5676133, 0.51373154, 0.70830995, 0.6759344, 0.5094966),
        T(0.51264906, 0.5449657, 0.69929224, 0.7196084, 0.6788409, 0.6048201, 0.5488066,
          0.5363483, 0.72345006, 0.5405681, 0.6089998, 0.70805573),
        T(0.5928766, 0.63519526, 0.65843326, 0.6217353, 0.64459175, 0.5350151, 0.7062603,
          0.55394423, 0.6501412, 0.5486432, 0.7080888, 0.675643),
        T(0.7090862, 0.61549497, 0.53033024, 0.7098962, 0.72101665, 0.7188572, 0.6981471,
          0.7136484, 0.5859967, 0.6871868, 0.65447533, 0.56007093),
        T(0.58580256, 0.5502003, 0.6148747, 0.64277065, 0.6857534, 0.5011686, 0.54080904,
          0.65560967, 0.56999725, 0.54757565, 0.609852, 0.5351395),
        T(0.7143652, 0.53502005, 0.70207745, 0.6875393, 0.7029301, 0.65189064, 0.70781386,
          0.5729237, 0.5160258, 0.69524366, 0.6165334, 0.5316028),
        T(0.6367116, 0.5886046, 0.56053656, 0.64915115, 0.65535223, 0.58132136, 0.67581826,
          0.6921457, 0.64890057, 0.7144876, 0.6201936, 0.6979384),
        T(0.57011, 0.6531807, 0.62503153, 0.6436198, 0.69175565, 0.6528884, 0.6487297,
          0.6395312, 0.6955445, 0.66967374, 0.64985913, 0.6532872)),
        T(T(0.51045823, 0.7136831, 0.56406343, 0.56233406, 0.5221792, 0.6315658, 0.7002062,
          0.68388414, 0.7203382, 0.5339054, 0.62687886, 0.5190161),
        T(0.6007161, 0.54905915, 0.5275296, 0.5509995, 0.6349218, 0.72120166, 0.59122944,
          0.56807214, 0.71899664, 0.6526436, 0.57267904, 0.67870134),
        T(0.5151846, 0.54783577, 0.5851861, 0.68118656, 0.71166825, 0.631233, 0.71900266,
          0.52196133, 0.7111365, 0.61995095, 0.70218617, 0.5590531),
        T(0.7129838, 0.6559077, 0.7258186, 0.5041189, 0.5232647, 0.7047582, 0.59610456,
          0.67488647, 0.71441, 0.5842877, 0.58227265, 0.5689087),
        T(0.6220621, 0.5836973, 0.7299364, 0.5582246, 0.50226533, 0.6958726, 0.51557744,
          0.5727451, 0.52065825, 0.64763504, 0.55392694, 0.7093481),
        T(0.6862833, 0.6981787, 0.60825187, 0.63988155, 0.5681973, 0.6164435, 0.5012094,
          0.5269813, 0.72196907, 0.672021, 0.5152003, 0.59994596),
        T(0.6534933, 0.62057513, 0.5725102, 0.7126337, 0.69655156, 0.52507395, 0.6930016,
          0.7185013, 0.7277586, 0.50503635, 0.6303666, 0.7210629),
        T(0.7096779, 0.72210556, 0.728121, 0.6906394, 0.53061163, 0.5837192, 0.59222233,
          0.65138894, 0.67794853, 0.5689136, 0.50981325, 0.54487646),
        T(0.56297135, 0.62408656, 0.50655365, 0.6549637, 0.53530365, 0.5023403, 0.6510051,
          0.6869589, 0.5829244, 0.6573664, 0.54007137, 0.7282872),
        T(0.6250854, 0.5283047, 0.5904026, 0.6528091, 0.55060863, 0.69158715, 0.538936,
          0.6800518, 0.6919966, 0.7258603, 0.6873867, 0.5875557),
        T(0.67806643, 0.699513, 0.52257764, 0.65697443, 0.6783283, 0.64929, 0.54697603,
          0.6097425, 0.688104, 0.71832335, 0.6101874, 0.5322427),
        T(0.5505245, 0.51022655, 0.72613287, 0.723738, 0.553964, 0.5327107, 0.59699506,
          0.58739096, 0.66101485, 0.6416125, 0.63273776, 0.61910945)))))


    output.almostEqual(expectedOutput, 1e-3) should be(true)
  }
}

class MaskPostProcessorSerialTest extends ModuleSerializationTest {
  override def test(): Unit = {
    val proposal = new MaskPostProcessor().setName("MaskPostProcessor")
    val labels = Tensor[Float](T(1, 3))
    val logits = Tensor[Float](2, 81, 18, 18).rand()
    runSerializationTest(proposal, T(logits, labels))
  }
}
